<?php
/**
 * Created by PhpStorm.
 * User: Daxu
 * Date: 2017/11/3
 * Time: 15:52
 */

namespace App\Services;


class Platform
{
    private $config = [];
    public function __construct($config)
    {
        $this->config = $config;
    }
    public function checkStudent($openid){
        $content = ["openid" => $openid];
        return $this->curl($content,$this->config['url'].'/wechat/authentication');
    }
    public function studentJoin($openid,$u_code){
        $content = ["openid" => $openid,"student_code"=>$u_code];
        return $this->curl($content,$this->config['url'].'/wechat/join');
    }
    public function relieve($openid){
        $content = ["openid" => $openid];
        return $this->curl($content,$this->config['url'].'/wechat/relieve');
    }
    public function curl($content,$url){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// post数据
        curl_setopt($ch, CURLOPT_POST, 1);
// post的变量
        curl_setopt($ch, CURLOPT_POSTFIELDS, $content);

        $output = curl_exec($ch);
        curl_close($ch);
        $result =json_decode($output);
        if(empty($result)||$result->success == false || empty($result->data)){
            return false;
        }
        return $result->data;
    }
}